#include "AspectEngine.h"

namespace agtk {

void DrawScreenAlignedQuad(void)
{
	glMatrixMode(GL_MODELVIEW);
	glPushMatrix();
	glLoadIdentity();
	glMatrixMode(GL_PROJECTION);
	glPushMatrix();
	glLoadIdentity();

	glBegin(GL_QUADS);
	glTexCoord2f(0.0f, 0.0f);
	glVertex3i(-1, -1, -1);
	glTexCoord2f(1.0f, 0.0f);
	glVertex3i(1, -1, -1);
	glTexCoord2f(1.0f, 1.0f);
	glVertex3i(1, 1, -1);
	glTexCoord2f(0.0f, 1.0f);
	glVertex3i(-1, 1, -1);
	glEnd();
	
	glPopMatrix();
	glMatrixMode(GL_MODELVIEW);
	glPopMatrix();
}

void DrawScreenQuad(Color &color, Vec2<int> &size, Vec2<int> &position)
{
	int x = position.Get(0);
	int y = position.Get(1);
	int w = size.Get(0);
	int h = size.Get(1);

	glColor4f(color.r, color.g, color.b, color.a);

	glMatrixMode(GL_MODELVIEW);
	glPushMatrix();
	glLoadIdentity();
	glMatrixMode(GL_PROJECTION);
	glPushMatrix();
	glLoadIdentity();
	gluOrtho2D (0, g_aspectEngine->GetWidth(), 0, g_aspectEngine->GetHeight());

	glDisable(GL_DEPTH_TEST);
	glEnable(GL_BLEND);
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);	

	glBegin(GL_QUADS);
	glTexCoord2f(0.0f, 0.0f);
	glVertex2i(x, y);
	glTexCoord2f(1.0f, 0.0f);
	glVertex2i(x+w, y);
	glTexCoord2f(1.0f, 1.0f);
	glVertex2i(x+w, y+h);
	glTexCoord2f(0.0f, 1.0f);
	glVertex2i(x, y+h);
	glEnd();

	glDisable(GL_BLEND);
	glEnable(GL_DEPTH_TEST);
	
	glPopMatrix();
	glMatrixMode(GL_MODELVIEW);
	glPopMatrix();

	glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
}

}